//<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    sitepageevent
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: WidgetSettings.php 6590 2010-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */

$menuitemsTable = Engine_Api::_ ()->getDbtable ( 'menuItems', 'core' );
$menuitems = $menuitemsTable->createRow ();
$menuitems->name = 'core_admin_main_plugins_sitepageextensions';
$menuitems->module = 'sitepage';
$menuitems->label = 'Directory/Pages - Extensions';
$menuitems->label = 'Directory/Pages - Extensions';
$menuitems->plugin = Null;
$menuitems->params = '{"route":"admin_default","module":"sitepage","controller":"extension", "action": "index"}';
$menuitems->menu = 'core_admin_main_plugins';
$menuitems->submenu = Null;
$menuitems->enabled = '1';
$menuitems->custom = '0';
$menuitems->order = '999';
$menuitems->save ();

$contentTable = Engine_Api::_ ()->getDbtable ( 'content', 'core' );
$contentTableName = $contentTable->info ( 'name' );
$pageTable = Engine_Api::_ ()->getDbtable ( 'pages', 'core' );
$pageTableName = $pageTable->info ( 'name' );
$selectPage = $pageTable->select ()->from ( $pageTableName, array ('page_id' ) )->where ( 'name =?', 'sitepage_index_home' )->limit ( 1 );
$fetchPageId = $selectPage->query ()->fetchAll ();
if (empty ( $fetchPageId )) {
	$pageCreate = $pageTable->createRow ();
	$pageCreate->name = 'sitepage_index_home';
	$pageCreate->displayname = 'Pages Home';
	$pageCreate->title = 'Pages Home';
	$pageCreate->description = 'This is the page home page.';
	$pageCreate->custom = 1;
	$pageCreate->save ();
	$page_id = $pageCreate->page_id;
	
	//INSERT MAIN CONTAINER
	$mainContainer = $contentTable->createRow ();
	$mainContainer->page_id = $page_id;
	$mainContainer->type = 'container';
	$mainContainer->name = 'main';
	$mainContainer->order = 2;
	$mainContainer->save ();
	$container_id = $mainContainer->content_id;
	
	//INSERT MAIN-MIDDLE CONTAINER
	$mainMiddleContainer = $contentTable->createRow ();
	$mainMiddleContainer->page_id = $page_id;
	$mainMiddleContainer->type = 'container';
	$mainMiddleContainer->name = 'middle';
	$mainMiddleContainer->parent_content_id = $container_id;
	$mainMiddleContainer->order = 6;
	$mainMiddleContainer->save ();
	$middle_id = $mainMiddleContainer->content_id;
	
	//INSERT MAIN-LEFT CONTAINER
	$mainLeftContainer = $contentTable->createRow ();
	$mainLeftContainer->page_id = $page_id;
	$mainLeftContainer->type = 'container';
	$mainLeftContainer->name = 'left';
	$mainLeftContainer->parent_content_id = $container_id;
	$mainLeftContainer->order = 4;
	$mainLeftContainer->save ();
	$left_id = $mainLeftContainer->content_id;
	
	//INSERT MAIN-RIGHT CONTAINER
	$mainRightContainer = $contentTable->createRow ();
	$mainRightContainer->page_id = $page_id;
	$mainRightContainer->type = 'container';
	$mainRightContainer->name = 'right';
	$mainRightContainer->parent_content_id = $container_id;
	$mainRightContainer->order = 5;
	$mainRightContainer->save ();
	$right_id = $mainRightContainer->content_id;
	
	//INSERT TOP CONTAINER
	$topContainer = $contentTable->createRow ();
	$topContainer->page_id = $page_id;
	$topContainer->type = 'container';
	$topContainer->name = 'top';
	$topContainer->order = 1;
	$topContainer->save ();
	$top_id = $topContainer->content_id;
	
	//INSERT TOP-MIDDLE CONTAINER
	$topMiddleContainer = $contentTable->createRow ();
	$topMiddleContainer->page_id = $page_id;
	$topMiddleContainer->type = 'container';
	$topMiddleContainer->name = 'middle';
	$topMiddleContainer->parent_content_id = $top_id;
	$topMiddleContainer->order = 1;
	$topMiddleContainer->save ();
	$top_middle_id = $topMiddleContainer->content_id;
	
	//INSERT "Page of the day" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.item-sitepage', $left_id, 1, "Page of the day", "true" );
	
	//INSERT NAVIGATION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.browsenevigation-sitepage', $top_middle_id, 2 );
	
	//INSERT ZERO PAGE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.zeropage-sitepage', $middle_id, 3 );
	
	//INSERT "Featured Pages" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.slideshow-sitepage', $middle_id, 4, "Featured Pages", "true" );
	
	//INSERT "Categories" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.categories', $middle_id, 5, "Categories", "true" );
	
	//INSERT RANDOM PAGES WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.recently-popular-random-sitepage', $middle_id, 6 );
	
	//INSERT SEARCH WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.search-sitepage', $right_id, 7 );
	
	//INSERT NEW PAGE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.newpage-sitepage', $right_id, 8 );
	
	//INSERT "Sponsored Pages" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.sponsored-sitepage', $right_id, 9, "Sponsored Pages", "true" );
	
	//INSERT TAG CLOUD WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.tagcloud-sitepage', $right_id, 10 );
	
	//INSERT "Recommended Pages" WIDGET
	$isModEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'suggestion' );
	if (! empty ( $isModEnabled )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'Suggestion.suggestion-sitepage', $right_id, 999, "Recommended Pages" );
	}
	
	//INSERT "Most Liked Pages" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.mostlikes-sitepage', $left_id, 11, "Most Liked Pages", "true" );
	
	//INSERT "Most Commented Pages" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.mostcommented-sitepage', $left_id, 12, "Most Commented Pages", "true" );
	
	//INSERT "Recently Viewed" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.recentview-sitepage', $left_id, 13, "Recently Viewed", "true" );
	
	//INSERT "Recently Viewed By Friends" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.recentfriend-sitepage', $left_id, 14, "Recently Viewed By Friends", "true" );

}

$selectPage = $pageTable->select ()->from ( $pageTableName, array ('page_id' ) )->where ( 'name =?', 'sitepage_index_index' )->limit ( 1 );
$page_id = $selectPage->query ()->fetchAll ();
if (empty ( $page_id )) {
	$pageCreate = $pageTable->createRow ();
	$pageCreate->name = 'sitepage_index_index';
	$pageCreate->displayname = 'Browse Pages';
	$pageCreate->title = 'Browse Pages';
	$pageCreate->description = 'This is the page browse page.';
	$pageCreate->custom = 1;
	$pageCreate->save ();
	$page_id = $pageCreate->page_id;
	
	//INSERT MAIN CONTAINER
	$mainContainer = $contentTable->createRow ();
	$mainContainer->page_id = $page_id;
	$mainContainer->type = 'container';
	$mainContainer->name = 'main';
	$mainContainer->order = 2;
	$mainContainer->save ();
	$container_id = $mainContainer->content_id;
	
	//INSERT MAIN - MIDDLE CONTAINER
	$mainMiddleContainer = $contentTable->createRow ();
	$mainMiddleContainer->page_id = $page_id;
	$mainMiddleContainer->type = 'container';
	$mainMiddleContainer->name = 'middle';
	$mainMiddleContainer->parent_content_id = $container_id;
	$mainMiddleContainer->order = 6;
	$mainMiddleContainer->save ();
	$middle_id = $mainMiddleContainer->content_id;
	
	//INSERT MAIN - RIGHT CONTAINER
	$mainRightContainer = $contentTable->createRow ();
	$mainRightContainer->page_id = $page_id;
	$mainRightContainer->type = 'container';
	$mainRightContainer->name = 'right';
	$mainRightContainer->parent_content_id = $container_id;
	$mainRightContainer->order = 5;
	$mainRightContainer->save ();
	$right_id = $mainRightContainer->content_id;
	
	//INSERT TOP CONTAINER
	$topContainer = $contentTable->createRow ();
	$topContainer->page_id = $page_id;
	$topContainer->type = 'container';
	$topContainer->name = 'top';
	$topContainer->order = 1;
	$topContainer->save ();
	$top_id = $topContainer->content_id;
	
	//INSERT TOP- MIDDLE CONTAINER
	$topMiddleContainer = $contentTable->createRow ();
	$topMiddleContainer->page_id = $page_id;
	$topMiddleContainer->type = 'container';
	$topMiddleContainer->name = 'middle';
	$topMiddleContainer->parent_content_id = $top_id;
	$topMiddleContainer->order = 6;
	$topMiddleContainer->save ();
	$top_middle_id = $topMiddleContainer->content_id;
	
	//INSERT NAVIGATION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.browsenevigation-sitepage', $top_middle_id, 1 );
	
	//INSERT NAVIGATION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.alphabeticsearch-sitepage', $top_middle_id, 2 );
	
	//INSERT PAGES WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.pages-sitepage', $middle_id, 2 );
	
	//INSERT "Categories" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.categories-sitepage', $right_id, 3, "Categories", "true" );
	
	//INSERT SEARCH PAGE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.search-sitepage', $right_id, 4 );
	
	//INSERT NEW PAGE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.newpage-sitepage', $right_id, 5 );
	
	//INSERT "Popular Locations" WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.popularlocations-sitepage', $right_id, 6, "Popular Locations" );
	
	//INSERT TAG CLOUD WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.tagcloud-sitepage', $right_id, 7 );
}

include_once APPLICATION_PATH . '/application/modules/Sitepage/controllers/AdminviewpagewidgetController.php';
$selectPage = $pageTable->select ()->from ( $pageTableName, array ('page_id' ) )->where ( 'name =?', 'user_profile_index' )->limit ( 1 );
$page_id = $selectPage->query ()->fetchAll ();
if (! empty ( $page_id )) {
	$page_id = $page_id [0] ['page_id'];
	$selectWidgetId = $contentTable->select ()->from ( $contentTableName, array ('content_id' ) )->where ( 'page_id =?', $page_id )->where ( 'type = ?', 'widget' )->where ( 'name = ?', 'core.container-tabs' )->limit ( 1 );
	$fetchWidgetContentId = $selectWidgetId->query ()->fetchAll ();
	if (! empty ( $fetchWidgetContentId )) {
		$tab_id = $fetchWidgetContentId [0] ['content_id'];
		$contentWidget = $contentTable->createRow ();
		$contentWidget->page_id = $page_id;
		$contentWidget->type = 'widget';
		$contentWidget->name = 'sitepage.profile-sitepage';
		$contentWidget->parent_content_id = $tab_id;
		$contentWidget->order = 999;
		$contentWidget->params = '{"title":"Pages","titleCount":true}';
		$contentWidget->save ();
	}
}

$tableContent = Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' );
$tableContentName = $tableContent->info ( 'name' );
$select = new Zend_Db_Select ( $db );
$select_page = $select->from ( 'engine4_core_pages', 'page_id' )->where ( 'name = ?', 'sitepage_index_view' )->limit ( 1 );
$page = $select_page->query ()->fetchAll ();
if (! empty ( $page )) {
	$page_id = $page [0] ['page_id'];
	//INSERT MAIN CONTAINER
	$mainContainer = $tableContent->createRow ();
	$mainContainer->page_id = $page_id;
	$mainContainer->type = 'container';
	$mainContainer->name = 'main';
	$mainContainer->order = 2;
	$mainContainer->save ();
	$container_id = $mainContainer->admincontent_id;
	
	//INSERT MAIN-MIDDLE CONTAINER
	$mainMiddleContainer = $tableContent->createRow ();
	$mainMiddleContainer->page_id = $page_id;
	$mainMiddleContainer->type = 'container';
	$mainMiddleContainer->name = 'middle';
	$mainMiddleContainer->parent_content_id = $container_id;
	$mainMiddleContainer->order = 6;
	$mainMiddleContainer->save ();
	$middle_id = $mainMiddleContainer->admincontent_id;
	
	//INSERT MAIN-LEFT CONTAINER
	$mainLeftContainer = $tableContent->createRow ();
	$mainLeftContainer->page_id = $page_id;
	$mainLeftContainer->type = 'container';
	$mainLeftContainer->name = 'left';
	$mainLeftContainer->parent_content_id = $container_id;
	$mainLeftContainer->order = 4;
	$mainLeftContainer->save ();
	$left_id = $mainLeftContainer->admincontent_id;
	$showmaxtab = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.showmore', 8 );
	
	//INSERT MAIN-MIDDLE TAB CONTAINER
	$middleTabContainer = $tableContent->createRow ();
	$middleTabContainer->page_id = $page_id;
	$middleTabContainer->type = 'widget';
	$middleTabContainer->name = 'core.container-tabs';
	$middleTabContainer->parent_content_id = $middle_id;
	$middleTabContainer->order = 7;
	$middleTabContainer->params = "{\"max\":\"$showmaxtab\"}";
	$middleTabContainer->save ();
	$middle_tab = $middleTabContainer->admincontent_id;
	
	//INSERTING THUMB PHOTO WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.thumbphoto-sitepage', $middle_id, 1 );
	
	//INSERTING TITLE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.title-sitepage', $middle_id, 2 );
	
	//INSERTING LIKE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.page-like-button', $middle_id, 3 );
	
	//INSERTING FACEBOOK LIKE WIDGET
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'facebookse' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'Facebookse.facebookse-sitepageprofilelike', $middle_id, 4 );
	}
	
	//INSERTING PHOTO STRIP WIDGET
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.photorecent-sitepage', $middle_id, 5 );
	}
	
	//INSERTING MAIN PHOTO WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.mainphoto-sitepage', $left_id, 10 );
	
	//INSERTING OPTIONS WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.options-sitepage', $left_id, 11 );
	
	//INSERTING INFORMATION WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.information-sitepage', $left_id, 14, 'Information', 'true' );
	
	//INSERTING WRITE SOMETHING ABOUT WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.page-like', $left_id, 15 );
	
	//INSERTING RATING WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagereview' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepagereview.ratings-sitepagereviews', $left_id, 16, 'Ratings' );
	}
	
	//INSERTING BADGE WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagebadge' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepagebadge.badge-sitepagebadge', $left_id, 17, 'Badge' );
	}
	
	//INSERTING YOU MAY ALSO LIKE WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.suggestedpage-sitepage', $left_id, 18, 'You May Also Like' );
	
	//INSERTING SOCIAL SHARE WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.socialshare-sitepage', $left_id, 19, 'Social Share' );
	
	//INSERTING FOUR SQUARE WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.foursquare-sitepage', $left_id, 20 );
	
	//INSERTING INSIGHTS WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.insights-sitepage', $left_id, 21, 'Insights' );
	
	//INSERTING FEATURED OWNER WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.featuredowner-sitepage', $left_id, 22, 'Owners' );
	
	//INSERTING ALBUM WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.albums-sitepage', $left_id, 23, 'Albums' );
	}
	
	//INSERTING PAGE PROFILE PLAYER WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepagemusic.profile-player', $left_id, 24 );
	}
	
	//INSERTING 'Linked Pages' WIDGET   
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.favourite-page', $left_id, 25, 'Linked Pages' );
	
	//INSERTING ACTIVITY FEED WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'socialengineaddon.feed', $middle_tab, 1, 'Updates', 'true' );
	
	//INSERTING INFORAMTION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.info-sitepage', $middle_tab, 2, 'Info', 'true' );
	
	//INSERTING OVERVIEW WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.overview-sitepage', $middle_tab, 3, 'Overview', 'true' );
	
	//INSERTING LOCATION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.location-sitepage', $middle_tab, 4, 'Map', 'true' );
	
	//INSERTING LINKS WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'core.profile-links', $middle_tab, 125, 'Links', 'true' );
}

?>